Skip to content

Add table extension to mdConverter goldmark renderer#498

Merged
jeremy merged 4 commits into
basecamp:mainfrom
savtrip:patch-1
Jul 24, 2026
Merged

Add table extension to mdConverter goldmark renderer#498
jeremy merged 4 commits into
basecamp:mainfrom
savtrip:patch-1

Conversation

@savtrip

@savtrip savtrip commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What

Hi guys,

This adds the goldmark table extension for rendering markdown tables to HTML that lexxy now supports in bc5.

Here are the docs for the table extension that I added: https://pkg.go.dev/github.com/yuin/goldmark#readme-built-in-extensions

Why

My agent was adding tables to descriptions of cards and todos (any rich text area) but I noticed the table was not rendering but instead showed the raw markdown.

Therefore, I looked into the code and discovered there was no table extension for goldmark (refer to the docs I linked above to see the table extension). Also, I noticed from the comment it says:

// mdConverter is the goldmark Markdown-to-HTML converter configured for Trix compatibility.

Therefore, I assume the team has not optimised for lexxy yet given it says Trix.

If my agent renders everything in HTML then the table works fine. But sometimes it chooses to do it in markdown and therefore I end up having the raw markdown content in my rich text (which obviously looks terrible lol).

If for whatever reason you guys aren't happy with the change then writing something in the SKILL file to say "Note: tables will not render if provided in markdown because the CLI does not convert them to HTML" would at least signal to the agent that it's not possible.

Testing

  • make check passes

I did not add any test cases in. I performed a cli test of adding a card and it worked successful. I did not want to add tests because I wanted to check if this was a change you guys were happy with.

EDIT: Screenshots

I added the screenshots below to show the problem in basecamp.

HTML

screenshot-2026-06-11-at-12-43-23

Markdown

screenshot-2026-06-11-at-12-42-44

Summary by cubic

Enable Markdown table rendering by adding the goldmark table extension; tables now render as HTML with align attributes so GFM alignment survives BC3 sanitization.

Also improves detection and safety: table-only Markdown is detected via the AST with a fast pre-check to skip parsing when no | or newline, IsHTML recognizes

, TUI editors refuse table-bearing content to prevent data loss, and HTML detection now also matches self-closing
; Basecamp skill docs updated.

Written for commit 5b5903a. Summary will update on new commits.

Review in cubic

Copilot AI review requested due to automatic review settings June 11, 2026 11:25
@github-actions github-actions Bot added the enhancement New feature or request label Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Markdown table support to the rich-text Markdown→HTML converter.

Changes:

  • Enable Goldmark’s extension.Table alongside extension.Strikethrough

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/richtext/richtext.go Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@flavorjones

Copy link
Copy Markdown
Member

Thanks for this. Just wanted to drop a note that the eventual goal is to have markdown conversion done server-side (not in the CLI). But that's going to be a few more weeks at least, so it may make sense to add this client-side for now. I'll defer to @jeremy!

@savtrip

savtrip commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

No worries Mike, thanks for the explanation, I was wondering why the conversion was done locally instead of server-side, makes sense now. Appreciate your help, have a great day.

@jeremy jeremy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — registering the table extension is exactly the fix for #405. One correction so column alignment survives BC3's sanitizer, plus some surrounding work that doesn't fit an inline suggestion.

The alignment gotcha (inline suggestion below): plain extension.Table emits alignment as style="text-align:…". BC3's ContentPipeline sanitizer strips inline style (only color/background-color survive) but whitelists the align attribute — verified in bc3 app/helpers/content_pipeline/sanitization.rb. Configuring the extension with TableCellAlignAttribute emits align="left"/align="right" instead, so GFM column alignment is preserved through sanitization. Bare <table> is still correct — BC3's WrapTablesFilter supplies the <figure class="lexxy-content__table-wrapper"> wrapper.

The rest (can't be inline): because the CLI can now author tables, a few adjacent paths need to change so tables aren't silently destroyed — IsMarkdown needs AST-based table detection (a table-only chat message is otherwise sent as raw pipes), IsHTML needs to recognize <table> (a plain table response otherwise leaks raw markup on display), and the TUI in-place editors need to fail closed on table-bearing content (HTMLToMarkdown has no table handling, so opening + resubmitting would flatten the table — round-tripping waits on BC3 #11986). I've pushed all of that, with tests and a skill-doc boundary note, as a reference branch you're welcome to fold in: fix/markdown-tables (commit 601b272). bin/ci is fully green on it.

Comment thread internal/richtext/richtext.go Outdated
savtrip and others added 2 commits July 22, 2026 16:13
Register goldmark's table extension in mdConverter so Markdown tables
convert to <table> HTML instead of leaking as raw pipe rows. Use the
align-attribute cell method rather than the default inline style, since
BC3's sanitizer whitelists the align attribute but strips style, so
column alignment survives sanitization. BC3's WrapTablesFilter supplies
the figure wrapper, so a bare <table> is correct.

Because the CLI can now author tables, guard against destroying them:

- IsMarkdown gains AST-based table detection so a table-only chat message
  is sent as HTML rather than verbatim pipes.
- IsHTML recognizes <table> so a plain table response is routed through
  the display converter instead of leaking raw markup to the reader.
- The TUI in-place editors (message body, comment, to-do description)
  fail closed on table-bearing content: HTMLToMarkdown has no table
  handling, so they refuse to open rather than flatten the table on
  resubmit. Round-trip editing waits on server-side Markdown (BC3 #11986).

Document the table boundary in the Basecamp skill.
Copilot AI review requested due to automatic review settings July 22, 2026 23:19
@github-actions github-actions Bot added tui Terminal UI tests Tests (unit and e2e) skills Agent skills labels Jul 22, 2026
@jeremy

jeremy commented Jul 22, 2026

Copy link
Copy Markdown
Member

@savtrip I pushed the reconciled work onto this branch, rebased onto current main, and stacked these on top:

  • Alignment correction: extension.NewTable(WithTableCellAlignMethod(TableCellAlignAttribute)) instead of plain extension.Table, so column alignment emits the whitelisted align attribute rather than the style BC3's sanitizer strips.
  • Because the CLI can now author tables: AST-based IsMarkdown table detection (table-only chat messages would otherwise send as raw pipes), IsHTML recognizes <table> (plain table responses would otherwise leak raw markup on display), and the TUI in-place editors fail closed on table-bearing content (HTMLToMarkdown has no table handling — round-tripping waits on BC3 #11986).
  • Tests for all of the above, plus the SKILL.md table boundary note.

bin/ci is fully green. Closed my earlier standalone PR (#560) — this branch is the single home for the fix. Fixes #405. Happy to adjust anything.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread internal/richtext/richtext.go Outdated
@jeremy jeremy added this to the v0.8.0 milestone Jul 22, 2026
The docstring claimed the detector matched self-closing table tags, but
the character class [\s>] excluded '/'. Add '/' so <table/> is caught,
keeping the boundary that prevents <tablefoo> from matching.
Copilot AI review requested due to automatic review settings July 23, 2026 00:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread internal/richtext/richtext.go
IsMarkdown runs hasMarkdownTable on every input that matches none of the
regex patterns — typically plain text on TUI submit/editor return. A GFM
table can't exist without both a cell-delimiting '|' and a delimiter row
on its own line, so skip the full parse when either is absent. This
mirrors goldmark's own behavior (it treats a CR-only table with no '\n'
as not a table), so no real table is missed.
Copilot AI review requested due to automatic review settings July 23, 2026 00:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@savtrip

savtrip commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Hi @jeremy excellent, thanks for adding the necessary robustness around the PR. The code looks good to me, I can't make comment on bc3 required changes (I run bc5) but it looks good to me.

If you were wanting further testing I am more than happy to contribute.

Thanks for getting this change, I've been wrangling with my agent for the last month to add tables in HTML, they love exporting to markdown lol -- let me know if you need anything from me.

@jeremy

jeremy commented Jul 24, 2026

Copy link
Copy Markdown
Member

Thanks @savtrip!

@jeremy
jeremy merged commit 763a5a1 into basecamp:main Jul 24, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request skills Agent skills tests Tests (unit and e2e) tui Terminal UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants